<?php
class Default_Model_Product extends Zend_Db_Table_Abstract
{
	protected $_name= "sanpham";
	
	public function getProducSes($id)
	{
		$row=$this->fetchAll('idTL='.$id);
		return $row;
	}
	public function updateProduct($id,$view)
	{
		$view++;
		$data=array('luotxem'=>$view); //'luotxem' la mot column trong table 'sanpham' trong CSDL
		$where='idSP='.$id;
		$this->update($data,$where); //su dung function update() cua CSDL.Cau lenh nay co nghia la 
									//thuc thi update 'luotxem' = view++ khi dieu kien 'where' duoc thoa man
									//Dieu kien 'where' o day co nghia la khi 'idSP'==$id dieu nay xay ra khi nguoi dung click vao 'xemchitiet',hoac 2 helper('san pham ban chay nhat','laptop moi ve') 
	}
	public function getProducCat($id)
	{
		$row=$this->fetchAll('idLoai='.$id);
		return $row;
	}
	public function getProduct($id)
	{
		$row=$this->fetchRow('idSP='.$id);
		return $row;
	}
	public function getallProduct()
	{
		$row=$this->fetchAll();
		return $row;
	}
	public function getProductFeater()
	{
		$row=$this->fetchAll(null,'Gia DESC',20,0);
		return $row;
	}
	public function getProductNew()
	{
		$row=$this->fetchAll(null,'NgayDang DESC',4,0);
		return $row;
	}
	public function getProductSell()
	{
		$row=$this->fetchAll(null,'luotxem DESC',4,0);
		
		return $row;
	}
	public function getSearch($txtKey,$category,$price1,$price2)
	{
		$tmp='1';
		if($txtKey)
			$tmp.=" AND TenSP LIKE '%".$txtKey."%'";
		if($category)
			$tmp.=' AND idLoai='.$category;
		if($price1 AND $price2)
			$tmp.=' AND Gia BETWEEN '.$price1.' AND '.$price2.'';

		$where=$tmp;
		
		$row=$this->fetchAll($where);
		return $row;
	}
	public function getSearchSell($variable)
	{
		switch ($variable) {
			case 1:
			$where='Gia > 30000 '; //Gia lon hon 30.000.000vnd vi trong ma nguon lay 'gia' them 3 so 000 vao sau.
								//Xem colum 'gia' trong table 'sanpham'.
			break;
			case 2:
			$where='Gia BETWEEN 15000 AND 30000';
			
			break;
			case 3:
			$where='Gia BETWEEN 7000 AND 15000';
			break;
			
			default:
			$where='Gia < 7000';	
			break;
		}
		
		$row=$this->fetchAll($where);
		return $row;
	}
}